#!/usr/local/env python
# -*- coding: utf-8 -*-
# @Time    : 2018/9/20 13:39
# @Author  : Kyy
# @Site    : 
# @File    : getdb.py
# @Software: PyCharm

from connmongo import MongoConn
import time

start = time.time()
conn = MongoConn()
res = conn.db['alibaba'].find({},{'_id':0})
rst = []
num = 0
for i in res:
    rst.append(i)
    num += 1
    print("当前条目数:%s" % num)

rows = ['company','contact_name','Company Name','Operational Address', \
        'Website','Website on alibabacom','Telephone','Mobile Phone','Fax',\
        'Address','Zip','Country/Region','Province/State','City']
import pandas as pd


company = [it.get(rows[0]) for it in rst]
contact_name = [it.get(rows[1]) for it in rst]
company_name = [it.get(rows[2]) for it in rst]
op_address = [it.get(rows[3]) for it in rst]
website = [it.get(rows[4]) for it in rst]
website_on_alibb =[it.get(rows[5]) for it in rst]
tel =[it.get(rows[6]) for it in rst]
mobile_phone = [it.get(rows[7]) for it in rst]
fax = [it.get(rows[8]) for it in rst]
address = [it.get(rows[9]) for it in rst]
zip = [it.get(rows[10]) for it in rst]
contry_region =[it.get(rows[11]) for it in rst]
provin_state = [it.get(rows[12]) for it in rst]
city = [it.get(rows[13]) for it in rst]

aa = pd.DataFrame({rows[i]:[it.get(rows[i]) for it in rst] for i in range(14)})
aa.to_excel("C:\\kyy\\项目\\1688\\alibaba.xlsx",header=True)
end = time.time() - start
print(end)
# print(rst[:5])